<?php
class ThongtindbsController extends AppController {

	var $name = 'Thongtindbs';

	function index() {
		$this->Thongtindb->recursive = 0;
		$this->set('thongtindbs', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid thongtindb', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('thongtindb', $this->Thongtindb->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Thongtindb->create();
			$this->data['Thongtindb']['sudung'] =$this->data['Thongtindb']['sd']; 
			if ($this->Thongtindb->save($this->data)) {
				$this->Session->setFlash(__('Đã thêm thuộc tính', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('Không thể thêm. Xin vui lòng thử lại', true));
			}
		}
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Không tồn tại thuộc tính', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data))
		{

			
			if ($this->Thongtindb->save($this->data)) 
			{
				
				$this->Session->setFlash(__('Đã Sửa', true));
				$this->redirect(array('action' => 'index'));
			}
			else 
			{
				$this->Session->setFlash(__('Không thể thêm. Xin vui lòng thử lại', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Thongtindb->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for thongtindb', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Thongtindb->delete($id)) {
			$this->Session->setFlash(__('Thongtindb deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Thongtindb was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
